<template>
  <div>
   <div>
     <h3 id="title">
       个人信息修改
     </h3>
   </div>
    <Back></Back>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm"  label-width="100px" class="demo-ruleForm">
    <el-form-item label="用户名" prop="n_name">
      <el-input v-model="ruleForm.n_name"></el-input>
    </el-form-item>
    <el-form-item label="登陆密码" prop="password">
      <el-input v-model="ruleForm.password"></el-input>
    </el-form-item>
    <el-form-item label="真实姓名" prop="real_name">
      <el-input v-model="ruleForm.real_name"></el-input>
    </el-form-item>
    <el-form-item label="电话号码" prop="phone">
      <el-input v-model="ruleForm.phone"></el-input>
    </el-form-item>
    <el-form-item label="身份证号" prop="IdCard">
      <el-input v-model="ruleForm.IdCard"></el-input>
    </el-form-item>
    <!--<el-form-item label="最后登陆时间" prop="end_time">
      <el-input v-model="ruleForm.end_time"></el-input>
    </el-form-item>
    <el-form-item label="注册时间" prop="r_time">
      <el-input v-model="ruleForm.r_time"></el-input>
    </el-form-item>-->

    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
  </div>
</template>

<script>
import back from '@/components/back/Return';
import { updateInfo } from '@/api/info';
export default {
name: "UpdateInfo",
  data() {
    return {
      ruleForm: {
        n_name: '',
        password:'',
        real_name: '',
        phone: '',
        IdCard: ''
      },
      rules: {
        n_name: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入登陆密码', trigger: 'blur' }
        ],
        real_name: [
          { type: 'date', required: true, message: '请输入用户真实姓名', trigger: 'blur' },
          { min: 2, max: 10, message: '请输入两个以上的字符', trigger: 'blur' }
        ],
        phone: [
          { type: 'date', required: true, message: '请输入11位电话号码', trigger: 'blur' },
          { min: 11, max: 11, message: '电话号码格式错误', trigger: 'blur' }
        ],
        IdCard: [
          { type: 'array', required: true, message: '请输入身份证号', trigger: 'blur' },
          { min: 18, max: 18, message: '身份证号码错误', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
          //发送请求
          updateInfo(this.ruleForm).then(respone=>{
            console.log(respone);
          }).catch(error=>{
            console.log(error);
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  components: {
    'Back': back
  }
}
</script>

<style scoped>
#title{
  line-height: 100px;
  text-align: center;
  color: #00a854;
}
</style>